//
//  RABookDetailBottomCell.m
//  ReadApp
//
//  Created by 飞猪 on 2018/11/8.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "RABookDetailBottomCell.h"
#import "RABookDetailModel.h"

@interface RABookDetailBottomCell ()

@property (nonatomic, strong) UILabel *titleLab;

@property (nonatomic, strong) UIImageView *arrowImg;

@property (nonatomic, strong) UIView *btmLine;

@end

@implementation RABookDetailBottomCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
    [self addSubViews];
  }
  return self;
}

- (void)addSubViews {
  
  self.backgroundColor = [UIColor whiteColor];
  self.contentView.backgroundColor = [UIColor whiteColor];
  self.selectionStyle = UITableViewCellSelectionStyleNone;
  
  [self.contentView addSubview:self.titleLab];
  [self.contentView addSubview:self.arrowImg];
  [self.contentView addSubview:self.btmLine];
  
  [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.left.bottom.mas_equalTo(self.contentView).mas_equalTo(UIEdgeInsetsMake(0, 10, 0, 0));
    if ([self.reuseIdentifier isEqualToString:@""]) {
      make.height.mas_equalTo(44.f);
    }
    else {
      make.height.mas_equalTo(50.f);
    }
  }];
  
  [self.arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.mas_equalTo(-10.f);
    make.centerY.mas_equalTo(0);
  }];
  
  [self.btmLine mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.left.bottom.mas_equalTo(0);
    make.height.mas_equalTo(0.5);
  }];

}

- (void)setModel:(RABookDetailModel *)model {
  _model = model;
  
  self.titleLab.hidden = NO;
  self.arrowImg.hidden = NO;
  self.btmLine.hidden = NO;
  self.titleLab.text = [NSString stringWithFormat:@"查看目录：共 %@ 章", _model.chapterCount];
  
}

- (UILabel *)titleLab {
  if (!_titleLab) {
    _titleLab = [UILabel new];
    _titleLab.font = [UIFont systemFontOfSize:14.f];
    _titleLab.textColor = [UIColor blackColor];
    _titleLab.hidden = YES;
  }
  return _titleLab;
}

- (UIImageView *)arrowImg {
  if (!_arrowImg) {
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right_arrow"]];
    imageView.userInteractionEnabled = NO;
    imageView.hidden = YES;
    
    _arrowImg = imageView;
  }
  return _arrowImg;
}

- (UIView *)btmLine {
  if (!_btmLine) {
    _btmLine = [[UIView alloc] init];
    _btmLine.backgroundColor = UIColorHex(ebebeb);
  }
  return _btmLine;
}

@end
